<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<html>
<head> 
	<title>Videshop POS</title> 
	<link href="../css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
	<f:view>
		<table border="0" cellpadding="0" cellspacing="10">
			<tr>
				<td colspan="2"><h1>Videoshop POS</h1></td>
			</tr>
			<tr>
				<td valign="top">
					<table border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td>
								<!-- User section -->
								<f:subview id="userSection">
									<jsp:include page="user.jsp"/>
								</f:subview>
							</td>
						</tr>
						<tr>
							<td>
								<!-- Menu section -->
								<f:subview id="menuSection">
									<jsp:include page="menu.jsp"/>
								</f:subview>
							</td>
						</tr>
					</table>
				</td>
				<td valign="top" class="mainSection">
					<c:choose>
						<c:when test="${!empty userSection.staff}">
							<h2>Return</h2>
							
							<c:if test="${!empty returnSection.rentals}">
								<h:panelGrid columns="2">
									<h:outputText styleClass="label" value="Customer id"/>
									<h:outputText styleClass="field" value="#{returnSection.customer.customerId}"/>
									<h:outputText styleClass="label" value="First Name"/>
									<h:outputText styleClass="field" value="#{returnSection.customer.firstName}"/>
									<h:outputText styleClass="label" value="Last Name"/>
									<h:outputText styleClass="field" value="#{returnSection.customer.lastName}"/>
								</h:panelGrid>
								
								<h:form id="returnForm">
									<h:dataTable 	id="returnTable" 
													styleClass="dataTable"
													columnClasses="returnTableTitleCopyIdColumn,returnTableImageColumn,returnTableTitleColumn,returnTablePriceColumn,returnTableActionColumn"
													value="#{returnSection.rentals}"
													var="rental"
									>
										<h:column headerClass="returnTableTitleCopyIdColumn">
											<f:facet name="header">
												<f:verbatim escape="true">Id</f:verbatim>
											</f:facet>
											<h:outputText value="#{rental.titleCopy.titleCopyId}"/>
										</h:column>
										<h:column headerClass="returnTableImageColumn">
											<f:facet name="header">
											</f:facet>
											<h:graphicImage url="#{rental.titleCopy.medium.title.iconUrl}"/>
										</h:column>
										<h:column headerClass="returnTableTitleColumn" footerClass="returnTablePriceColumn">
											<f:facet name="header">
												<f:verbatim escape="true">Title</f:verbatim>
											</f:facet>
											<h:outputText value="#{rental.titleCopy.medium.title.titleName}"/>
											<f:facet name="footer">
												<f:verbatim escape="true">Total</f:verbatim>
											</f:facet>
										</h:column>
										<h:column headerClass="returnTablePriceColumn" footerClass="returnTablePriceColumn">
											<f:facet name="header">
												<f:verbatim escape="true">Pelnaty</f:verbatim>
											</f:facet>
											<h:outputText value="#{rental.finalCharge}">
												<f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2"/>
											</h:outputText>
											<f:facet name="footer">
												<h:outputText value="#{returnSection.totalPrice}">
													<f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2"/>
												</h:outputText>
											</f:facet>
										</h:column>
										<h:column headerClass="returnTableActionColumn">
											<f:facet name="header">
												<f:verbatim escape="true">Action</f:verbatim>
											</f:facet>
											<h:commandLink styleClass="button" action="#{returnSection.delete}"
											>
												<f:verbatim escape="true">Delete</f:verbatim>
											</h:commandLink>
										</h:column>
									</h:dataTable>
								</h:form>
							</c:if>
							<h:form>
								<h:panelGrid columns="3">
									<h:outputText styleClass="label" value="Enter Id"/>
									<h:inputText styleClass="text200" value="#{returnSection.titleCopyId}"/>
									<h:commandLink styleClass="button" action="#{returnSection.add}">
										<f:verbatim escape="true">Add</f:verbatim>
									</h:commandLink>
									<c:if test="${!empty returnSection.rentals}">
										<h:commandLink styleClass="button" action="#{returnSection.finish}"
										>
											<f:verbatim escape="true">Finish</f:verbatim>
										</h:commandLink>
										<h:commandLink styleClass="button" action="#{returnSection.cancel}">
											<f:verbatim escape="true">Cancel</f:verbatim>
										</h:commandLink>
									</c:if>
								</h:panelGrid>
							</h:form>
						</c:when>
						<c:otherwise>
							Please login
						</c:otherwise>
					</c:choose>
				</td>
			</tr>
		</table>
	</f:view>
</html>